package cn.uikit.demo.widget

import android.animation.ValueAnimator
import android.content.Context
import android.content.Intent
import android.graphics.BitmapFactory
import android.os.Bundle
import android.text.method.ScrollingMovementMethod
import androidx.core.content.res.ResourcesCompat
import androidx.lifecycle.lifecycleScope
import cn.uikit.demo.R
import cn.uikit.demo.databinding.ActivityCustomViewTestBinding
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import sivin.uikit.framework.BindingActivity
import sivin.uikit.framework.setFullScreen


class CustomViewTestActivity : BindingActivity<ActivityCustomViewTestBinding>(
    ActivityCustomViewTestBinding::inflate
) {
    companion object {
        fun launch(context: Context) {
            val startIntent = Intent(context, CustomViewTestActivity::class.java)
            context.startActivity(startIntent)
        }
    }

    override fun onViewCreate(savedInstanceState: Bundle?) {
        super.onViewCreate(savedInstanceState)
        binding.pieView.updateData(listOf(10, 60, 30))
        binding.progressView.setProgress(100f)
        ValueAnimator.ofFloat(50f, 0f).apply {
            duration = 1000
            addUpdateListener { animated ->
                val value = animated.animatedValue as Float
                binding.progressView.setProgress(value)
            }
        }.start()

        lifecycleScope.launch {
            delay(1000)
            binding.ktSportTarget.setDegrees(359)
            binding.ktSportTarget.invalidate()
            binding.scrollText.movementMethod = ScrollingMovementMethod.getInstance()
        }

    }
}